﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace df
{
    public partial class login : share
    {
        public login()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void submit_Click(object sender, EventArgs e)
        {
            string nm = name.Text;
            string pw = password.Text;

            var para = new Dictionary<string, object>();
            para.Add("nm", nm);
            para.Add("pw", pw);
            var rt = post(config.api_login, para);
            if (rt != null)
            {

                err(err, rt["msg"].ToString());
                //登录成功
                if (rt["status"].ToInt32() > 0)
                {
                    string token = rt["result"]["token"].ToString();
                    updateConfig(config.token, token);
                    updateConfig(config.cloud_nm, nm);
                    updateConfig(config.cloud_pw, pw);

                    config.cloudNm = nm;
                    config.cloudPw = pw;
                    DialogResult = DialogResult.OK;



                }

            }





        }

        private void cancel_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void reg_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            reg r = new reg();

            if (r.ShowDialog() == DialogResult.OK)
            {
                err.Text = r.err.Text;
                r.Dispose();
            }
        }
    }
}
